<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Task</title>
</head>
<body>

<script>
    //task 1
    var str = 'sdf-dfsfd-fdgdg-123';
    var strList = str.split('-');
    console.info(str ,'<=字符串分割=>', strList);
    // task 2
    var strSearch = str.slice(3, str.length - 3);
    var strReplace = '';
    for (var i = 0; i < strSearch.length; i++) {
        strReplace += '*';
    }
    var strHide = str.replace(strSearch, strReplace);
    console.info('替换字符串: ', strHide);

    //task3
    function arrayToString(array) {
        return array.toString();
    }

    console.info('数组转换为字符串', arrayToString(strList));

    //task4
    function arrayTransposeRandom(array, newArray) {
        var length = array.length;
        if (length === 1) {
            newArray.push(array[0]);
            return newArray;
        }
        var random = Math.ceil(Math.random() * length) - 1;
        newArray.push(array[random]);
        // 删除数组
        array.splice(random, 1);
        return arrayTransposeRandom(array, newArray);
    }

    var index = 0;
    while (index < 3) {
        index++;
        var arr = [1, 2, 3, 4, 5, 6, 7, 8, 9];
        console.info(i + '->随即排序:', arrayTransposeRandom(arr, []));
    }

    // task 5
    var array = [23564, 5656, 545, 654456, 45656, 16515, 4515, 456445];

    function computeMin(array) {
        var min = array[0];
        for (var i in array) {
            if (min > array[i]) {
                min = array[i];
            }
        }
        return min;
    }

    function computeMax(array) {
        var max = array[0];
        for (var i in array) {
            if (max < array[i]) {
                max = array[i];
            }
        }
        return max;
    }

    console.info('原数组是:', array);
    console.info('最大值：', computeMax(array));
    console.info('最小值:', computeMin(array));

    //task 6
    function randomNumber(min, max) {
        var range = max - min + 1;
        return Math.ceil(Math.random() * range) + min - 1;
    }

    console.info('随机12-999的整数', randomNumber(12, 999));

    //task7
    function computeData(f1, f2) {
        console.info('原来第一个参数是:' + f1, '原来第一个参数是:' + f2);
        var newF1 = round(f1);
        var newF2 = decimalRound(f2, 2);
        console.info('第一个参数四舍五入后是:' + newF1, '第二个参数保留小数位的四舍五入:' + newF2);
    }

    computeData(Math.random() * 10, Math.random() * 10);

    function round(num) {
        return Math.round(num);
    }

    function decimalRound(num, max) {
        var multiple = Math.pow(10, max);
        return Math.round(num * multiple) / multiple.toFixed(2);
    }
</script>
</body>
</html>